<!DOCTYPE html>
<html lang="zh-CN">
    <!-- title -->


    

<!-- keywords -->



<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="author" content="Lolipop">
    <meta name="renderer" content="webkit">
    <meta name="copyright" content="Lolipop">
    
        <meta name="keywords" content="Lolipop,frontend,full-stack,前端,全栈">
    
    <meta name="description" content="">
    <meta name="description" content="本文旨在基于 Koa 从零开始搭建一个简单的 Telegram Bot 应用服务，帮助笔者更好地将爱传递给 Telegram！ 本文假设您已对 Node.js 和 Koa 有一定的了解。 初始化 Koa 项目Koa 是为 Node.js 设计的下一代 Web 框架，其幕后开发者主要来自知名的 Express 团队。 尽管使用 koa-generator 来初始化 Koa 项目是一个不错的选择，但笔">
<meta property="og:type" content="article">
<meta property="og:title" content="从零开始使用 Telegram Bot">
<meta property="og:url" content="https://lolipopj.github.io/2022/01/08/start-telegram-bot/index.html">
<meta property="og:site_name" content="Lolipop">
<meta property="og:description" content="本文旨在基于 Koa 从零开始搭建一个简单的 Telegram Bot 应用服务，帮助笔者更好地将爱传递给 Telegram！ 本文假设您已对 Node.js 和 Koa 有一定的了解。 初始化 Koa 项目Koa 是为 Node.js 设计的下一代 Web 框架，其幕后开发者主要来自知名的 Express 团队。 尽管使用 koa-generator 来初始化 Koa 项目是一个不错的选择，但笔">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/lolipopj/LolipopJ.github.io/2022/01/08/start-telegram-bot/create-bot.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/lolipopj/LolipopJ.github.io/2022/01/08/start-telegram-bot/ngrok.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/lolipopj/LolipopJ.github.io/2022/01/08/start-telegram-bot/forward-to-my-channel.png">
<meta property="article:published_time" content="2022-01-08T16:00:00.000Z">
<meta property="article:modified_time" content="2022-01-10T16:00:00.000Z">
<meta property="article:author" content="Lolipop">
<meta property="article:tag" content="Node">
<meta property="article:tag" content="PostgreSQL">
<meta property="article:tag" content="Telegram">
<meta property="article:tag" content="Bot">
<meta property="article:tag" content="Koa">
<meta property="article:tag" content="Sequelize">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/lolipopj/LolipopJ.github.io/2022/01/08/start-telegram-bot/create-bot.png">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="icon" href="https://cdn.jsdelivr.net/gh/lolipopj/LolipopJ.github.io/static/assets/favicon.ico">
    
    <title>从零开始使用 Telegram Bot · Lolipop&#39;s Studio</title>
    <!-- /*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
/* This file is meant as a standalone workflow for
- testing support for link[rel=preload]
- enabling async CSS loading in browsers that do not support rel=preload
- applying rel preload css once loaded, whether supported or not.
*/ -->
<script>
    (function (w) {
        'use strict'
        // rel=preload support test
        if (!w.loadCSS) {
            w.loadCSS = function () {}
        }
        // define on the loadCSS obj
        var rp = (loadCSS.relpreload = {})
        // rel=preload feature support test
        // runs once and returns a function for compat purposes
        rp.support = (function () {
            var ret
            try {
                ret = w.document.createElement('link').relList.supports('preload')
            } catch (e) {
                ret = false
            }
            return function () {
                return ret
            }
        })()

        // if preload isn't supported, get an asynchronous load by using a non-matching media attribute
        // then change that media back to its intended value on load
        rp.bindMediaToggle = function (link) {
            // remember existing media attr for ultimate state, or default to 'all'
            var finalMedia = link.media || 'all'

            function enableStylesheet() {
                link.media = finalMedia
            }

            // bind load handlers to enable media
            if (link.addEventListener) {
                link.addEventListener('load', enableStylesheet)
            } else if (link.attachEvent) {
                link.attachEvent('onload', enableStylesheet)
            }

            // Set rel and non-applicable media type to start an async request
            // note: timeout allows this to happen async to let rendering continue in IE
            setTimeout(function () {
                link.rel = 'stylesheet'
                link.media = 'only x'
            })
            // also enable media after 3 seconds,
            // which will catch very old browsers (android 2.x, old firefox) that don't support onload on link
            setTimeout(enableStylesheet, 3000)
        }

        // loop through link elements in DOM
        rp.poly = function () {
            // double check this to prevent external calls from running
            if (rp.support()) {
                return
            }
            var links = w.document.getElementsByTagName('link')
            for (var i = 0; i < links.length; i++) {
                var link = links[i]
                // qualify links to those with rel=preload and as=style attrs
                if (
                    link.rel === 'preload' &&
                    link.getAttribute('as') === 'style' &&
                    !link.getAttribute('data-loadcss')
                ) {
                    // prevent rerunning on link
                    link.setAttribute('data-loadcss', true)
                    // bind listeners to toggle media back
                    rp.bindMediaToggle(link)
                }
            }
        }

        // if unsupported, run the polyfill
        if (!rp.support()) {
            // run once at least
            rp.poly()

            // rerun poly on an interval until onload
            var run = w.setInterval(rp.poly, 500)
            if (w.addEventListener) {
                w.addEventListener('load', function () {
                    rp.poly()
                    w.clearInterval(run)
                })
            } else if (w.attachEvent) {
                w.attachEvent('onload', function () {
                    rp.poly()
                    w.clearInterval(run)
                })
            }
        }

        // commonjs
        if (typeof exports !== 'undefined') {
            exports.loadCSS = loadCSS
        } else {
            w.loadCSS = loadCSS
        }
    })(typeof global !== 'undefined' ? global : this)
</script>

    <style type="text/css">
    @font-face {
        font-family: 'Oswald-Regular';
        src: url("/font/Oswald-Regular.ttf");
    }

    body {
        margin: 0;
    }

    header,
    footer,
    .back-top,
    .sidebar,
    .container,
    .site-intro-meta,
    .toc-wrapper {
        display: none;
    }

    .site-intro {
        position: relative;
        z-index: 3;
        width: 100%;
        /* height: 50vh; */
        overflow: hidden;
    }

    .site-intro-placeholder {
        position: absolute;
        z-index: -2;
        top: 0;
        left: 0;
        width: calc(100% + 300px);
        height: 100%;
        background: repeating-linear-gradient(-45deg, #444 0, #444 80px, #333 80px, #333 160px);
        background-position: center center;
        transform: translate3d(-226px, 0, 0);
        animation: gradient-move 2.5s ease-out 0s infinite;
    }

    @keyframes gradient-move {
        0% {
            transform: translate3d(-226px, 0, 0);
        }
        100% {
            transform: translate3d(0, 0, 0);
        }
    }
</style>

    <link rel="preload" href="/css/style.css?v=20211217" as="style" onload="this.onload=null;this.rel='stylesheet'">
    <link rel="preload" href="/css/dark.css?v=20211217" as="style">
    <link rel="stylesheet" href="/css/dark.css">
    <link rel="stylesheet" href="/css/mobile.css?v=20211217" media="(max-width: 960px)">
    <link rel="preload" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
    <link rel="preload" href="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js" as="script">
    <link rel="preload" href="/scripts/main.js?v=20211217" as="script">
    <link rel="preload" href="/scripts/dark.js?v=20211217" as="script">
    <link rel="preload" href="/font/Oswald-Regular.ttf" as="font" crossorigin>
    <link rel="preload" href="https://at.alicdn.com/t/font_327081_1dta1rlogw17zaor.woff" as="font" crossorigin>
    <!-- algolia -->
    
        <script>
            var hits = JSON.parse('{"per_page":10}')
            var labels = JSON.parse('{"input_placeholder":"搜索博客","hits_empty":"Ops，我未能提供任何搜索结果：${query}","hits_stats":"在 ${time} ms 内找到了 ${hits} 个结果"}')

            var algolia = {
                applicationID: 'V9YD7AWBOS',
                apiKey: '5cb206cb0658a9daff865eef79de4bc4',
                indexName: 'lolipopJ.github.io',
                hits: hits,
                labels: labels
            }
        </script>
    
    <!-- 百度统计  -->
    
    <!-- 谷歌统计  -->
    
<meta name="generator" content="Hexo 5.4.1"><link rel="alternate" href="/atom.xml" title="Lolipop" type="application/atom+xml">
</head>

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
    <script type="text/javascript">
        if (typeof window.$ == undefined) {
            console.warn('jquery load from jsdelivr failed, will load local script')
            document.write('<script src="/lib/jquery.min.js" />')
        }
    </script>
    
        <body class="post-body">
    
        <!-- header -->
        <header class="header header-mobile">
    <!-- top read progress line -->
    <div class="header-element">
        <div class="read-progress read-progress-feature"></div>
    </div>
    <!-- sidebar menu button -->
    <div class="header-element">
        
            <div class="header-sidebar-menu header-sidebar-menu-rounded">
        
            
                <i class="fas fa-bars"></i>
            
        </div>
    </div>
    <!-- header actions -->
    <div class="header-actions">
        <!-- theme mode switch button -->
        <span class="header-theme-btn header-element">
            <i class="fas fa-adjust"></i>
        </span>
        <!-- back to home page text -->
        <span class="home-link header-element">
            <a href=/>Lolipop's Studio.</a>
        </span>
    </div>
    <!-- toggle banner for post layout -->
    
        
            <div class="banner banner-clean">
        
            <div class="blog-title header-element">
                <a href="/">Lolipop&#39;s Studio.</a>
            </div>
            <div class="post-title header-element">
                <a href="#" class="post-name">从零开始使用 Telegram Bot</a>
            </div>
        </div>
    
</header>

        <!-- fixed footer -->
        <footer class="footer-fixed">
    <!-- back to top button -->
    <div class="footer-fixed-element">
        
            <div class="back-top back-top-hidden back-top-rounded">
        
        
            <i class="fas fa-chevron-up"></i>
        
        </div>
    </div>
</footer>

        <!-- wrapper -->
        <div class="wrapper">
            <div class="site-intro" style="







    height:50vh;

">
    
    <!-- 主页  -->
    
        
    <!-- 404页  -->
            
    <div class="site-intro-placeholder"></div>
    <div class="site-intro-img" style="background-image: url(https://source.unsplash.com/1600x900/?coder)"></div>
    <div class="site-intro-meta">
        <!-- 标题  -->
        <h1 class="intro-title">
            <!-- 主页  -->
            
                从零开始使用 Telegram Bot
            <!-- 404 -->
            
        </h1>
        <!-- 副标题 -->
        <p class="intro-subtitle">
            <!-- 主页副标题  -->
            
                
            <!-- 404 -->
            
        </p>
        <!-- 文章页 meta -->
        
            <div class="post-intros">
                <!-- 文章页标签  -->
                
                    <div class= post-intro-tags >
    
        
        
            
        
        
        <span class="post-category" data-categories="后端开发"">
            <i class="fas fa-folder post-category-icon"></i>
            <span class="post-category-text">
                后端开发
            </span>
        </span>
    
    
        <a class="post-tag" href="javascript:void(0);" data-tags="Node">Node</a>
    
        <a class="post-tag" href="javascript:void(0);" data-tags="PostgreSQL">PostgreSQL</a>
    
        <a class="post-tag" href="javascript:void(0);" data-tags="Telegram">Telegram</a>
    
        <a class="post-tag" href="javascript:void(0);" data-tags="Bot">Bot</a>
    
        <a class="post-tag" href="javascript:void(0);" data-tags="Koa">Koa</a>
    
        <a class="post-tag" href="javascript:void(0);" data-tags="Sequelize">Sequelize</a>
    
</div>

                
                
                    <div class="post-intro-read">
                        <span>字数统计: <span class="post-count word-count">3.1k</span>阅读时长: <span class="post-count reading-time">13 min</span></span>
                    </div>
                
                <div class="post-intro-meta">
                    <!-- 撰写日期 -->
                    <span class="iconfont-archer post-intro-calander">&#xe676;</span>
                    <span class="post-intro-time">2022/01/09</span>
                    <!-- busuanzi -->
                    
                        <span id="busuanzi_container_page_pv" class="busuanzi-pv">
                            <span class="iconfont-archer post-intro-busuanzi">&#xe602;</span>
                            <span id="busuanzi_value_page_pv"></span>
                        </span>
                    
                    <!-- 文章分享 -->
                    <span class="share-wrapper">
                        <span class="iconfont-archer share-icon">&#xe71d;</span>
                        <span class="share-text">Share</span>
                        <ul class="share-list">
                            <li class="iconfont-archer share-qr" data-type="qr">&#xe75b;
                                <div class="share-qrcode"></div>
                            </li>
                            <li class="iconfont-archer" data-type="weibo">&#xe619;</li>
                            <li class="iconfont-archer" data-type="qzone">&#xe62e;</li>
                            <li class="iconfont-archer" data-type="twitter">&#xe634;</li>
                            <li class="iconfont-archer" data-type="facebook">&#xe67a;</li>
                        </ul>
                    </span>
                </div>
            </div>
        
    </div>
</div>

            <script>
  // get user agent
  function getBrowserVersions() {
    var u = window.navigator.userAgent
    return {
      userAgent: u,
      trident: u.indexOf('Trident') > -1, //IE内核
      presto: u.indexOf('Presto') > -1, //opera内核
      webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
      gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
      mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
      ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
      android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
      iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者安卓QQ浏览器
      iPad: u.indexOf('iPad') > -1, //是否为iPad
      webApp: u.indexOf('Safari') == -1, //是否为web应用程序，没有头部与底部
      weixin: u.indexOf('MicroMessenger') == -1, //是否为微信浏览器
      uc: u.indexOf('UCBrowser') > -1, //是否为android下的UC浏览器
    }
  }
  var browser = {
    versions: getBrowserVersions(),
  }
  console.log('userAgent: ' + browser.versions.userAgent)

  // callback
  function fontLoaded() {
    console.log('font loaded')
    if (document.getElementsByClassName('site-intro-meta')) {
      document
        .getElementsByClassName('intro-title')[0]
        .classList.add('intro-fade-in')
      document
        .getElementsByClassName('intro-subtitle')[0]
        .classList.add('intro-fade-in')
      var postIntros = document.getElementsByClassName('post-intros')[0]
      if (postIntros) {
        postIntros.classList.add('post-fade-in')
      }
    }
  }

  // UC不支持跨域，所以直接显示
  function asyncCb() {
    if (browser.versions.uc) {
      console.log('UCBrowser')
      fontLoaded()
    } else {
      WebFont.load({
        custom: {
          families: ['Oswald-Regular'],
        },
        loading: function () {
          // 所有字体开始加载
          // console.log('font loading');
        },
        active: function () {
          // 所有字体已渲染
          fontLoaded()
        },
        inactive: function () {
          // 字体预加载失败，无效字体或浏览器不支持加载
          console.log('inactive: timeout')
          fontLoaded()
        },
        timeout: 5000, // Set the timeout to two seconds
      })
    }
  }

  function asyncErr() {
    console.warn('script load from CDN failed, will load local script')
  }

  // load webfont-loader async, and add callback function
  function async(u, cb, err) {
    var d = document,
      t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0]
    o.src = u
    if (cb) {
      o.addEventListener(
        'load',
        function (e) {
          cb(null, e)
        },
        false
      )
    }
    if (err) {
      o.addEventListener(
        'error',
        function (e) {
          err(null, e)
        },
        false
      )
    }
    s.parentNode.insertBefore(o, s)
  }

  var asyncLoadWithFallBack = function (arr, success, reject) {
    var currReject = function () {
      reject()
      arr.shift()
      if (arr.length) async(arr[0], success, currReject)
    }

    async(arr[0], success, currReject)
  }

  asyncLoadWithFallBack(
    [
      'https://cdn.jsdelivr.net/npm/webfontloader@1.6.28/webfontloader.min.js',
      'https://cdn.bootcss.com/webfont/1.6.28/webfontloader.js',
      "/lib/webfontloader.min.js",
    ],
    asyncCb,
    asyncErr
  )
</script>

            <img class="loading" src="/assets/loading.svg" style="display: block; margin: 6rem auto 0 auto; width: 6rem; height: 6rem;" />
            <div class="container container-unloaded">
                <main class="main post-page">
    <article class="article-entry">
        <p>本文旨在基于 Koa 从零开始搭建一个简单的 Telegram Bot 应用服务，帮助笔者更好地将爱传递给 Telegram！</p>
<p>本文假设您已对 Node.js 和 Koa 有一定的了解。</p>
<h2 id="初始化-Koa-项目"><a href="#初始化-Koa-项目" class="headerlink" title="初始化 Koa 项目"></a>初始化 Koa 项目</h2><p><a target="_blank" rel="noopener" href="https://koajs.com/">Koa</a> 是为 Node.js 设计的下一代 Web 框架，其幕后开发者主要来自知名的 Express 团队。</p>
<p>尽管使用 <a target="_blank" rel="noopener" href="https://github.com/i5ting/koa-generator">koa-generator</a> 来初始化 Koa 项目是一个不错的选择，但笔者还是喜欢从头开始的感觉。</p>
<p>那么首先，新建文件夹并进入，使用 <code>npm init</code> 初始化 <code>package.json</code>。</p>
<p>安装必要的依赖：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install koa koa-router koa-bodyparser dotenv</span><br></pre></td></tr></table></figure>

<p>安装开发依赖：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -D nodemon</span><br></pre></td></tr></table></figure>

<p>安装服务器部署时使用的依赖：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install pm2</span><br></pre></td></tr></table></figure>

<p>为了简便，这里笔者使用了别人进行封装后的 Telegram Bot API 库 <a target="_blank" rel="noopener" href="https://github.com/yagop/node-telegram-bot-api">node-telegram-bot-api</a>：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install node-telegram-bot-api</span><br></pre></td></tr></table></figure>

<p>规划项目目录结构大致如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">.</span><br><span class="line">├── .env</span><br><span class="line">├── app.js</span><br><span class="line">├── package.json</span><br><span class="line">├── bin</span><br><span class="line">│   └── www.js</span><br><span class="line">└── routes</span><br><span class="line">│   └── index.js</span><br><span class="line">└── service</span><br><span class="line">    ├── bot.js</span><br><span class="line">    └── index.js</span><br></pre></td></tr></table></figure>

<p>其中，<code>.env</code> 为环境配置文件，包括 Telegram Bot Token 在内的信息在此处配置；<code>bin/www.js</code> 为项目启动时执行的文件，这意味着在配置脚本命令时，应当使用 <code>nodemon bin/www</code> 及 <code>pm2 start bin/www</code>；<code>routes</code> 目录为路由目录，用来存放可调用的接口；最后，<code>service</code> 目录为服务目录，在这里连接 Bot 和数据库，并执行定时任务。</p>
<h2 id="连接到-Telegram-Bot"><a href="#连接到-Telegram-Bot" class="headerlink" title="连接到 Telegram Bot"></a>连接到 Telegram Bot</h2><h3 id="创建新的-Bot"><a href="#创建新的-Bot" class="headerlink" title="创建新的 Bot"></a>创建新的 Bot</h3><p>首先，通过在 Telegram 上与 <a target="_blank" rel="noopener" href="https://core.telegram.org/bots#6-botfather">BotFather</a> 交互，创建一个新的 Telegram Bot。</p>
<p><img src="https://cdn.jsdelivr.net/gh/lolipopj/LolipopJ.github.io/2022/01/08/start-telegram-bot/create-bot.png" alt="create a new bot"></p>
<p>记录下当中的 <strong>HTTP API</strong> 的值即 Telegram Bot Token，作为项目的环境变量保存，切勿上传到远程代码仓库中。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> token = process.<span class="property">env</span>.<span class="property">TELEGRAM_BOT_TOKEN</span></span><br></pre></td></tr></table></figure>

<h3 id="与-Bot-建立连接"><a href="#与-Bot-建立连接" class="headerlink" title="与 Bot 建立连接"></a>与 Bot 建立连接</h3><p>我们的项目可能无法直接访问到 Telegram 的服务器，可以使用 <a target="_blank" rel="noopener" href="https://github.com/mattcg/socks5-https-client"><strong>SOCKS5 代理</strong></a>解决这个问题：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="title class_">TelegramBot</span> = <span class="built_in">require</span>(<span class="string">&#x27;node-telegram-bot-api&#x27;</span>)</span><br><span class="line"><span class="keyword">const</span> proxySocks5Agent = <span class="built_in">require</span>(<span class="string">&#x27;socks5-https-client/lib/Agent&#x27;</span>)</span><br><span class="line"></span><br><span class="line">requestOptions = &#123;</span><br><span class="line">  <span class="attr">agentClass</span>: proxySocks5Agent,</span><br><span class="line">  <span class="attr">agentOptions</span>: &#123;</span><br><span class="line">    <span class="attr">socksHost</span>: process.<span class="property">env</span>.<span class="property">PROXY_SOCKS5_HOST</span>,</span><br><span class="line">    <span class="attr">socksPort</span>: process.<span class="property">env</span>.<span class="property">PROXY_SOCKS5_PORT</span>,</span><br><span class="line">    <span class="attr">socksUsername</span>: process.<span class="property">env</span>.<span class="property">PROXY_SOCKS5_USERNAME</span>,</span><br><span class="line">    <span class="attr">socksPassword</span>: process.<span class="property">env</span>.<span class="property">PROXY_SOCKS5_PASSWORD</span>,</span><br><span class="line">  &#125;,</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> bot = <span class="keyword">new</span> <span class="title class_">TelegramBot</span>(token, &#123;</span><br><span class="line">  <span class="attr">polling</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="attr">request</span>: requestOptions,</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>如何 SOCKS5 工作不正常（<a target="_blank" rel="noopener" href="https://github.com/yagop/node-telegram-bot-api/issues/696#issuecomment-613023532">这是</a>一个可能的原因），也可以尝试使用 <strong>HTTP 代理</strong>：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="title class_">TelegramBot</span> = <span class="built_in">require</span>(<span class="string">&#x27;node-telegram-bot-api&#x27;</span>)</span><br><span class="line"></span><br><span class="line">requestOptions = &#123;</span><br><span class="line">  <span class="attr">proxy</span>: process.<span class="property">env</span>.<span class="property">PROXY_HTTP</span>,</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> bot = <span class="keyword">new</span> <span class="title class_">TelegramBot</span>(token, &#123;</span><br><span class="line">  <span class="attr">polling</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="attr">request</span>: requestOptions,</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>对 Bot 进行测试，添加如下代码：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">bot.<span class="title function_">onText</span>(<span class="regexp">/\/start/</span>, <span class="function">(<span class="params">msg</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// console.log(msg)</span></span><br><span class="line">  bot.<span class="title function_">sendMessage</span>(msg.<span class="property">chat</span>.<span class="property">id</span>, <span class="string">&#x27;Hi, this is Telly Bot!&#x27;</span>)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>打开 Telegram，对 Bot 发送 <code>/start</code>，看看是否会得到 <code>Hi, this is Telly Bot!</code> 的回应。</p>
<h3 id="使用网络钩子与-Bot-交互"><a href="#使用网络钩子与-Bot-交互" class="headerlink" title="使用网络钩子与 Bot 交互"></a>使用网络钩子与 Bot 交互</h3><p>Telegram Bot 可以通过轮询（polling）和网络钩子（webhook）两种不同的方式来获取用户发送的消息，在前面的代码中，我们使用的是轮询的方式。</p>
<p>轮询的方式无需额外的配置，更适合本地快速进行开发测试；而网络钩子的方式更适合项目部署。那么，一个健全的 Telegram Bot 应当使用<strong>网络钩子</strong>的方式来实现。</p>
<p>为了接收用户对 Telegram Bot 发送的消息，在网络钩子的方式中，我们需要一个 <strong>HTTPS 协议的公网地址</strong>，除了直接使用自己的服务器，还可以怎么办呢？别急，有 <a target="_blank" rel="noopener" href="https://ngrok.com/">ngrok</a> 为我们排忧解难：它是一款反向代理工具，可以将本地的地址映射到公网上去。</p>
<p><img src="https://cdn.jsdelivr.net/gh/lolipopj/LolipopJ.github.io/2022/01/08/start-telegram-bot/ngrok.png" alt="ngrok"></p>
<p>如上图所示，当 ngrok 运行时，Telegram Bot 发向 <code>https://a75b-182-141-75-13.ngrok.io</code> 的请求，将转发给运行在本地 <code>http://localhost:4000</code> 上的程序。</p>
<p>这样，只需要同时运行我们的项目和 ngrok，我们就可以正常地接收到信息并进行处理了。修改连接 Bot 的代码如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> bot = <span class="keyword">new</span> <span class="title class_">TelegramBot</span>(token, &#123;</span><br><span class="line">  <span class="attr">request</span>: requestOptions,</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">bot.<span class="title function_">setWebHook</span>(<span class="string">`<span class="subst">$&#123;process.env.WEBHOOK_HOST&#125;</span>/bot<span class="subst">$&#123;token&#125;</span>`</span>)</span><br><span class="line"></span><br><span class="line">globalThis.<span class="property">bot</span> = bot</span><br></pre></td></tr></table></figure>

<p>现在，Telegram 上机器人收到的消息会立即发送给我们的服务器。最后，在服务器需要处理接收到的 POST 类型请求 <code>/bot$&#123;TELEGRAM_BOT_TOKEN&#125;</code>，告知 Telegram 我们已经收到新的消息了。可以在 <code>routes/index.js</code> 中添加代码如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">router.<span class="title function_">post</span>(<span class="string">`bot<span class="subst">$&#123;token&#125;</span>`</span>, <span class="function">(<span class="params">ctx</span>) =&gt;</span> &#123;</span><br><span class="line">  globalThis.<span class="property">bot</span>.<span class="title function_">processUpdate</span>(ctx.<span class="property">request</span>.<span class="property">body</span>)</span><br><span class="line">  ctx.<span class="property">status</span> = <span class="number">200</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>需要补充的是，通过上面代码中 Bot API 库提供的 <a target="_blank" rel="noopener" href="https://github.com/yagop/node-telegram-bot-api/blob/master/doc/api.md#telegrambotprocessupdateupdate"><code>processUpdate</code></a> 方法，可以对接收到的消息进行相应的处理，触发正确的事件并执行回调方法。</p>
<p>现在，我们的机器人将不再笨拙地轮询 Telegram 服务器，查看是否有未处理的消息，而是静静等待 Telegram 服务器发送过来的请求。</p>
<h3 id="Bot-起始脚手架"><a href="#Bot-起始脚手架" class="headerlink" title="Bot 起始脚手架"></a>Bot 起始脚手架</h3><p>万事俱备，接下来就是根据自己的需求进行开发的时间了。</p>
<p><a target="_blank" rel="noopener" href="https://github.com/LolipopJ/telly-bot/tree/acbe0b122eb164dd3a44d95ed216877cbb9b0464">这里</a>是笔者简单配置好的项目代码，可以作为 Start-up 供君参考。</p>
<h2 id="获取-Github-Issues-的评论并转发给-Telegram-频道"><a href="#获取-Github-Issues-的评论并转发给-Telegram-频道" class="headerlink" title="获取 Github Issues 的评论并转发给 Telegram 频道"></a>获取 Github Issues 的评论并转发给 Telegram 频道</h2><p><a target="_blank" rel="noopener" href="https://billc.io/">Chen 先生</a>自己的 Telegram 频道会定时发送他更新的推文，笔者也想整一个，最简单的实现方式是申请一个 Twitter 开发者账号，定时调用 API 获取最新推文信息即可 —— 但是没能申请到。暂退一步，先把笔者在 Github Issues 上的碎碎念同步给频道吧。</p>
<p>接下来的内容假设您已对 PostgreSQL 和数据库 ORM 工具有一定的了解。</p>
<h3 id="连接到数据库"><a href="#连接到数据库" class="headerlink" title="连接到数据库"></a>连接到数据库</h3><p>同步功能需要数据库的支持，当然也为了未来更多功能的实现，在这里，先与本机的数据库建立连接。以 <a target="_blank" rel="noopener" href="https://www.enterprisedb.com/downloads/postgres-postgresql-downloads">PostgreSQL</a> 为例，首先安装 <a target="_blank" rel="noopener" href="https://github.com/brianc/node-postgres">node-postgres</a> 库：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install pg</span><br></pre></td></tr></table></figure>

<p>新建文件 <code>config.js</code> 来存储连接到数据库的配置：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> config = &#123;</span><br><span class="line">  <span class="attr">database</span>: &#123;</span><br><span class="line">    <span class="attr">postgresql</span>: &#123;</span><br><span class="line">      <span class="attr">host</span>: <span class="string">&#x27;localhost&#x27;</span>,</span><br><span class="line">      <span class="attr">port</span>: <span class="number">5432</span>,</span><br><span class="line">      <span class="attr">database</span>: <span class="string">&#x27;telly_bot_db&#x27;</span>,</span><br><span class="line">      <span class="attr">user</span>: <span class="string">&#x27;telly_bot_db_user&#x27;</span>,</span><br><span class="line">      <span class="attr">password</span>: <span class="string">&#x27;telly_bot_db_pwd&#x27;</span>,</span><br><span class="line">      <span class="attr">timezone</span>: <span class="string">&#x27;+08:00&#x27;</span>,</span><br><span class="line">    &#125;,</span><br><span class="line">  &#125;,</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="variable language_">module</span>.<span class="property">exports</span> = config</span><br></pre></td></tr></table></figure>

<h3 id="使用-ORM-管理数据库"><a href="#使用-ORM-管理数据库" class="headerlink" title="使用 ORM 管理数据库"></a>使用 ORM 管理数据库</h3><p>通过 ORM 工具来对数据库进行管理与查询，可以避免手动运维的窘境。这里选用 <a target="_blank" rel="noopener" href="https://github.com/sequelize/sequelize">Sequelize</a> 库，安装必要的依赖：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install sequelize pg-hstore</span><br></pre></td></tr></table></figure>

<p>修改 <code>db/index.js</code> 代码如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> &#123; <span class="title class_">Sequelize</span> &#125; = <span class="built_in">require</span>(<span class="string">&#x27;sequelize&#x27;</span>)</span><br><span class="line"><span class="keyword">const</span> pgsqlConfig = <span class="built_in">require</span>(<span class="string">&#x27;../config&#x27;</span>).<span class="property">database</span>.<span class="property">postgresql</span></span><br><span class="line"><span class="keyword">const</span> options = &#123;</span><br><span class="line">  <span class="attr">timezone</span>: pgsqlConfig.<span class="property">timezone</span> || <span class="string">&#x27;+08:00&#x27;</span>,</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">const</span> sequelize = <span class="keyword">new</span> <span class="title class_">Sequelize</span>(</span><br><span class="line">  <span class="string">`postgres://<span class="subst">$&#123;pgsqlConfig.user&#125;</span>:<span class="subst">$&#123;pgsqlConfig.password&#125;</span>@<span class="subst">$&#123;pgsqlConfig.host&#125;</span>:<span class="subst">$&#123;pgsqlConfig.port&#125;</span>/<span class="subst">$&#123;pgsqlConfig.database&#125;</span>`</span>,</span><br><span class="line">  options</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">;(<span class="keyword">async</span> () =&gt; &#123;</span><br><span class="line">  <span class="keyword">try</span> &#123;</span><br><span class="line">    <span class="keyword">await</span> sequelize.<span class="title function_">authenticate</span>()</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(</span><br><span class="line">      <span class="string">`Connection with <span class="subst">$&#123;pgsqlConfig.database&#125;</span> has been established successfully.`</span></span><br><span class="line">    )</span><br><span class="line">    <span class="keyword">await</span> sequelize.<span class="title function_">sync</span>(&#123; <span class="attr">alter</span>: <span class="literal">true</span> &#125;)</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;All models were synchronized successfully.&#x27;</span>)</span><br><span class="line">  &#125; <span class="keyword">catch</span> (error) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">error</span>(</span><br><span class="line">      <span class="string">`Unable to connect to the database <span class="subst">$&#123;pgsqlConfig.database&#125;</span>:`</span>,</span><br><span class="line">      error</span><br><span class="line">    )</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)()</span><br><span class="line"></span><br><span class="line"><span class="variable language_">module</span>.<span class="property">exports</span> = sequelize</span><br></pre></td></tr></table></figure>

<p>为了实现自动转发 Github Issues 中的评论，我们需要一张数据表来存储上一次转发的评论（或编辑记录）的<strong>最后更新日期</strong>（<code>lastUpdateCommentAt</code>)。这样，下一次执行任务时，只需要查看该日期之后是否有新的评论（或编辑记录）就可以了。对于每一个 Issue，都会在该表中创建一条数据。为 Sequelize 添加模型 <code>db/model/ServiceGithubIssueComment.js</code> 如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> &#123; <span class="title class_">DataTypes</span> &#125; = <span class="built_in">require</span>(<span class="string">&#x27;sequelize&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="variable language_">module</span>.<span class="property">exports</span> = &#123;</span><br><span class="line">  <span class="comment">// The ID of the forwarding Github Issue service</span></span><br><span class="line">  <span class="attr">id</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="title class_">DataTypes</span>.<span class="property">INTEGER</span>,</span><br><span class="line">    <span class="attr">autoIncrement</span>: <span class="literal">true</span>,</span><br><span class="line">    <span class="attr">primaryKey</span>: <span class="literal">true</span>,</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">// Url of Github Issue. Example: $&#123;USERNAME&#125;/$&#123;REPOSITORY&#125;/issues/$&#123;ISSUE_NUM&#125;</span></span><br><span class="line">  <span class="attr">issueUrl</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="title class_">DataTypes</span>.<span class="property">TEXT</span>,</span><br><span class="line">    <span class="attr">allowNull</span>: <span class="literal">false</span>,</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">// Only forward the comments of these users, empty means forward all</span></span><br><span class="line">  <span class="attr">issueUserId</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="title class_">DataTypes</span>.<span class="title function_">ARRAY</span>(<span class="title class_">DataTypes</span>.<span class="property">TEXT</span>),</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">// The ID of the channel to which the comment was forwarded</span></span><br><span class="line">  <span class="attr">forwardChannelId</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="title class_">DataTypes</span>.<span class="property">TEXT</span>,</span><br><span class="line">    <span class="attr">allowNull</span>: <span class="literal">false</span>,</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">// The last date the issue comments were updated</span></span><br><span class="line">  <span class="attr">lastUpdateCommentAt</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="title class_">DataTypes</span>.<span class="property">DATE</span>,</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">// Date the service was last run</span></span><br><span class="line">  <span class="attr">lastExecServiceAt</span>: &#123;</span><br><span class="line">    <span class="attr">type</span>: <span class="title class_">DataTypes</span>.<span class="property">DATE</span>,</span><br><span class="line">  &#125;,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>一个模型将成为数据库中的一张数据表。向 <code>db/index.js</code> 中添加如下代码：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> serviceGithubIssueCommentModel = <span class="built_in">require</span>(<span class="string">&#x27;./model/ServiceGithubIssueComment&#x27;</span>)</span><br><span class="line">sequelize.<span class="title function_">define</span>(</span><br><span class="line">  <span class="string">&#x27;ServiceGithubIssueComment&#x27;</span>,</span><br><span class="line">  serviceGithubIssueCommentModel</span><br><span class="line">)</span><br><span class="line"><span class="comment">// sequelize.sync(&#123; alter: true &#125;)</span></span><br></pre></td></tr></table></figure>

<p>注意，将模型绑定给 sequelize 对象的操作 <code>sequelize.define()</code> 需要放在 <code>sequelize.sync()</code> 方法之前。</p>
<p>当 <code>sequelize.define()</code> 执行完成后，我们可以随时使用 <code>sequelize.models.ServiceGithubIssueComment</code> 来获取模型实例。通过模型实例，我们就可以在对应的数据表中执行各种 SQL 查询语句了。</p>
<h3 id="获取指定-Issue-中的最新评论"><a href="#获取指定-Issue-中的最新评论" class="headerlink" title="获取指定 Issue 中的最新评论"></a>获取指定 Issue 中的最新评论</h3><p>Github REST API 文档推荐使用 <a target="_blank" rel="noopener" href="https://github.com/octokit/core.js">@octokit/core</a> 库来执行请求：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install @octokit/core</span><br></pre></td></tr></table></figure>

<p>向 <code>config.js</code> 中添加相应的配置。以获取笔者的<a target="_blank" rel="noopener" href="https://github.com/LolipopJ/LolipopJ/issues/2">碎碎念</a>为例：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> config = &#123;</span><br><span class="line">  <span class="attr">github</span>: &#123;</span><br><span class="line">    <span class="attr">forwardIssueComment</span>: &#123;</span><br><span class="line">      <span class="attr">duration</span>: <span class="number">3600</span>,</span><br><span class="line">      <span class="attr">task</span>: [</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="attr">owner</span>: <span class="string">&#x27;LolipopJ&#x27;</span>,</span><br><span class="line">          <span class="attr">repo</span>: <span class="string">&#x27;LolipopJ&#x27;</span>,</span><br><span class="line">          <span class="attr">issueNumber</span>: <span class="number">2</span>,</span><br><span class="line">          <span class="attr">issueUserId</span>: [<span class="number">42314340</span>],</span><br><span class="line">          <span class="attr">forwardChannelId</span>: <span class="string">&#x27;@lolipop_thoughts&#x27;</span>,</span><br><span class="line">          <span class="attr">since</span>: <span class="string">&#x27;2022-01-01T00:00:00.000Z&#x27;</span>,</span><br><span class="line">        &#125;,</span><br><span class="line">      ],</span><br><span class="line">    &#125;,</span><br><span class="line">  &#125;,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>其中，<code>duration</code> 为两次执行期间间隔的时间（秒）。此外，配置中存在 <code>issueUserId</code> 项，这是因为我们可能只想要转发自己发送的评论，在后面只需要根据该项过滤该用户 ID 的评论即可（可以通过 <code>https://api.github.com/users/your_github_user_name</code> 查看指定 Github 账户的 ID）。</p>
<p><a target="_blank" rel="noopener" href="https://docs.github.com/en/rest/reference/issues#list-issue-comments">这里</a>是获取指定 Issues 中的评论的方法。编写 <code>service/github.js</code> 代码如下（<strong>仅做参考</strong>：代码截取实现功能的部分，刨除提高鲁棒性的部分，也去除了第一次执行的部分）：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> &#123; <span class="title class_">Octokit</span> &#125; = <span class="built_in">require</span>(<span class="string">&#x27;@octokit/core&#x27;</span>)</span><br><span class="line"><span class="keyword">const</span> config = <span class="built_in">require</span>(<span class="string">&#x27;../config&#x27;</span>).<span class="property">github</span></span><br><span class="line"><span class="keyword">const</span> octokit = <span class="keyword">new</span> <span class="title class_">Octokit</span>(octokitOptions)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> bot = globalThis.<span class="property">bot</span></span><br><span class="line"><span class="keyword">const</span> sequelize = globalThis.<span class="property">sequelize</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> forwardGithubIssueComment = <span class="keyword">async</span> <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">  <span class="keyword">const</span> issues = config.<span class="property">forwardIssueComment</span>.<span class="property">task</span></span><br><span class="line">  <span class="keyword">const</span> <span class="title class_">ServiceGithubIssueComment</span> = sequelize.<span class="property">models</span>.<span class="property">ServiceGithubIssueComment</span></span><br><span class="line"></span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">const</span> issue <span class="keyword">of</span> issues) &#123;</span><br><span class="line">    <span class="keyword">const</span> owner = issue.<span class="property">owner</span></span><br><span class="line">    <span class="keyword">const</span> repo = issue.<span class="property">repo</span></span><br><span class="line">    <span class="keyword">const</span> issueNumber = issue.<span class="property">issueNumber</span></span><br><span class="line">    <span class="keyword">const</span> forwardChannelId = issue.<span class="property">forwardChannelId</span></span><br><span class="line">    <span class="keyword">const</span> issueUserId = issue.<span class="property">issueUserId</span></span><br><span class="line">    <span class="keyword">const</span> issueUrl = <span class="string">`<span class="subst">$&#123;owner&#125;</span>/<span class="subst">$&#123;repo&#125;</span>/issues/<span class="subst">$&#123;issueNumber&#125;</span>`</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> queryConfig = &#123;</span><br><span class="line">      issueUrl,</span><br><span class="line">      issueUserId,</span><br><span class="line">      forwardChannelId,</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">const</span> perPage = <span class="number">100</span></span><br><span class="line">    <span class="keyword">let</span> page = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 查询 Github Issues 的评论的最后更新日期 lastUpdateCommentAt</span></span><br><span class="line">    <span class="keyword">const</span> issueServiceInfo = <span class="keyword">await</span> <span class="title class_">ServiceGithubIssueComment</span>.<span class="title function_">findOne</span>(&#123;</span><br><span class="line">      <span class="attr">where</span>: queryConfig,</span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="keyword">const</span> lastUpdateCommentDate = issueServiceInfo.<span class="property">dataValues</span>.<span class="property">lastUpdateCommentAt</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 将 lastUpdateCommentAt 加上 1ms 作为下一次查询的起始日期</span></span><br><span class="line">    <span class="keyword">const</span> since = <span class="keyword">new</span> <span class="title class_">Date</span>(</span><br><span class="line">      <span class="keyword">new</span> <span class="title class_">Date</span>(lastUpdateCommentDate).<span class="title function_">getTime</span>() + <span class="number">1</span></span><br><span class="line">    ).<span class="title function_">toISOString</span>()</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 调用 Github API 获取指定 issue 的评论信息</span></span><br><span class="line">    <span class="comment">// 查询的评论更新日期从 since 开始</span></span><br><span class="line">    <span class="keyword">let</span> issueComments = []</span><br><span class="line">    <span class="keyword">while</span> (issueComments.<span class="property">length</span> === perPage * page) &#123;</span><br><span class="line">      ++page</span><br><span class="line">      <span class="keyword">const</span> res = <span class="keyword">await</span> octokit.<span class="title function_">request</span>(</span><br><span class="line">        <span class="string">&#x27;GET /repos/&#123;owner&#125;/&#123;repo&#125;/issues/&#123;issue_number&#125;/comments&#x27;</span>,</span><br><span class="line">        &#123;</span><br><span class="line">          owner,</span><br><span class="line">          repo,</span><br><span class="line">          <span class="attr">issue_number</span>: issueNumber,</span><br><span class="line">          since,</span><br><span class="line">          <span class="attr">per_page</span>: perPage,</span><br><span class="line">          page,</span><br><span class="line">        &#125;</span><br><span class="line">      )</span><br><span class="line">      issueComments = issueComments.<span class="title function_">concat</span>(res.<span class="property">data</span>)</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 如果设置了 issueUserId 项，则只保留数组中用户 ID 的评论</span></span><br><span class="line">    <span class="keyword">if</span> (<span class="title class_">Array</span>.<span class="title function_">isArray</span>(issueUserId) &amp;&amp; issueUserId.<span class="property">length</span> &gt; <span class="number">0</span>) &#123;</span><br><span class="line">      issueComments = issueComments.<span class="title function_">filter</span>(<span class="function">(<span class="params">comment</span>) =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">const</span> commentUserId = comment.<span class="property">user</span>.<span class="property">id</span></span><br><span class="line">        <span class="keyword">if</span> (issueUserId.<span class="title function_">includes</span>(commentUserId)) &#123;</span><br><span class="line">          <span class="keyword">return</span> <span class="literal">true</span></span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">          <span class="keyword">return</span> <span class="literal">false</span></span><br><span class="line">        &#125;</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>如果 Issue 存放在私人仓库中，则需要用到 <a target="_blank" rel="noopener" href="https://github.com/settings/tokens/new?scopes=repo">Personal Access Token</a> 进行鉴权。在创建 <code>octokit</code> 对象时传递相应参数：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> octokitOptions = &#123;&#125;</span><br><span class="line"><span class="keyword">const</span> authToken = process.<span class="property">env</span>.<span class="property">GITHUB_PERSONAL_ACCESS_TOKEN</span></span><br><span class="line"><span class="keyword">if</span> (authToken) &#123;</span><br><span class="line">  octokitOptions.<span class="property">auth</span> = authToken</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">const</span> octokit = <span class="keyword">new</span> <span class="title class_">Octokit</span>(octokitOptions)</span><br></pre></td></tr></table></figure>

<h3 id="定时转发评论到-Telegram-频道"><a href="#定时转发评论到-Telegram-频道" class="headerlink" title="定时转发评论到 Telegram 频道"></a>定时转发评论到 Telegram 频道</h3><p>由于 Github Issues 中的评论为 Markdown 格式，在转发到频道时，就需要对内容进行解析。幸运的是，Telegram Bot 的 <a target="_blank" rel="noopener" href="https://core.telegram.org/bots/api#sendmessage"><code>sendMessage()</code></a> 方法可以设置 <code>parse_mode</code> 选项，可以将<strong>大部分</strong>的 Markdown 内容顺利解析为正确的消息样式。但不幸的是，由于 Telegram 本身的一些限制，对于一些无法解析的符号会报错，针对这一部分评论，笔者选择直接发送评论的网页地址作为替代。</p>
<p>继续编写 <code>service/github.js</code> 代码如下（<strong>仅做参考</strong>）：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (issueComments.<span class="property">length</span> &gt; <span class="number">0</span>) &#123;</span><br><span class="line">  <span class="keyword">let</span> lastUpdateCommentAt = <span class="keyword">new</span> <span class="title class_">Date</span>(<span class="number">0</span>).<span class="title function_">toISOString</span>()</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 转发评论到 Telegram 频道</span></span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">const</span> issueComment <span class="keyword">of</span> issueComments) &#123;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">      <span class="keyword">await</span> bot.<span class="title function_">sendMessage</span>(</span><br><span class="line">        forwardChannelId,</span><br><span class="line">        issueComment.<span class="property">body</span>,</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="attr">parse_mode</span>: <span class="string">&#x27;MarkdownV2&#x27;</span>,</span><br><span class="line">        &#125;</span><br><span class="line">      )</span><br><span class="line">    &#125; <span class="keyword">catch</span> (error) &#123;</span><br><span class="line">      <span class="keyword">await</span> bot.<span class="title function_">sendMessage</span>(</span><br><span class="line">        forwardChannelId,</span><br><span class="line">        issueComment.<span class="property">html_url</span>,</span><br><span class="line">      )</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> issueCommentUpdatedAt = issueComment.<span class="property">updated_at</span></span><br><span class="line">    <span class="keyword">if</span> (issueCommentUpdatedAt &gt; lastUpdateCommentAt) &#123;</span><br><span class="line">      lastUpdateCommentAt = issueCommentUpdatedAt</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 维护数据库，保存 Github Issue 评论的最后更新日期</span></span><br><span class="line">  <span class="keyword">await</span> <span class="title class_">ServiceGithubIssueComment</span>.<span class="title function_">update</span>(</span><br><span class="line">    &#123;</span><br><span class="line">      lastUpdateCommentAt,</span><br><span class="line">      <span class="attr">lastExecServiceAt</span>: <span class="keyword">new</span> <span class="title class_">Date</span>().<span class="title function_">toISOString</span>(),</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">where</span>: queryConfig,</span><br><span class="line">    &#125;</span><br><span class="line">  )</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>到这里，我们已经基本实现了所需要的全部功能。最后需要做的事情，就是设置每隔一定时间自动运行此服务，持续获取最新的评论信息。这里笔者用到了 <code>toad-scheduler</code> 库：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install toad-scheduler</span><br></pre></td></tr></table></figure>

<p>在 <code>service/index.js</code> 中编写计划任务代码如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> &#123;</span><br><span class="line">  <span class="title class_">ToadScheduler</span>,</span><br><span class="line">  <span class="title class_">SimpleIntervalJob</span>,</span><br><span class="line">  <span class="title class_">AsyncTask</span>,</span><br><span class="line">&#125; = <span class="built_in">require</span>(<span class="string">&#x27;toad-scheduler&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> githubService = <span class="built_in">require</span>(<span class="string">&#x27;./github&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> config = <span class="built_in">require</span>(<span class="string">&#x27;../config&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> scheduler = <span class="keyword">new</span> <span class="title class_">ToadScheduler</span>()</span><br><span class="line"><span class="keyword">const</span> taskForwardGithubIssueComment = <span class="keyword">new</span> <span class="title class_">AsyncTask</span>(</span><br><span class="line">  <span class="string">&#x27;Forward Github Issue Comment&#x27;</span>,</span><br><span class="line">  <span class="keyword">async</span> () =&gt; &#123;</span><br><span class="line">    <span class="keyword">await</span> githubService.<span class="title function_">forwardGithubIssueComment</span>()</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="function">(<span class="params">error</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">error</span>(error)</span><br><span class="line">  &#125;</span><br><span class="line">)</span><br><span class="line"><span class="keyword">const</span> jobForwardGithubIssueComment = <span class="keyword">new</span> <span class="title class_">SimpleIntervalJob</span>(</span><br><span class="line">  &#123;</span><br><span class="line">    <span class="attr">seconds</span>: config.<span class="property">github</span>.<span class="property">forwardIssueComment</span>.<span class="property">duration</span>,</span><br><span class="line">    <span class="attr">runImmediately</span>: <span class="literal">true</span>,</span><br><span class="line">  &#125;,</span><br><span class="line">  taskForwardGithubIssueComment</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">scheduler.<span class="title function_">addSimpleIntervalJob</span>(jobForwardGithubIssueComment)</span><br></pre></td></tr></table></figure>

<p>一切就绪，运行我们的 Bot 程序！</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm run pm2</span><br></pre></td></tr></table></figure>

<p>笔者的频道顺利收到了来自 Github Issue 中的评论信息！</p>
<p><img src="https://cdn.jsdelivr.net/gh/lolipopj/LolipopJ.github.io/2022/01/08/start-telegram-bot/forward-to-my-channel.png" alt="Forward Github Issue&#39;s comments to my channel"></p>
<p>仍然，该服务还有许多可以优化的地方，例如：当评论发生更新时，应编辑已发送的频道消息为最新评论内容，而不是重新发一条新的消息等。不再在此文赘述。</p>
<h2 id="参考文章"><a href="#参考文章" class="headerlink" title="参考文章"></a>参考文章</h2><ul>
<li><a target="_blank" rel="noopener" href="https://www.wandouip.com/t5i13823/">开发一个 Telegram Bot</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md">node-telegram-bot-api usage</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/leobloise/node-telegram-bot-api-wb-tutorial">How to set webhooks using express local server and NGROK</a></li>
</ul>

    </article>
    <!-- license -->
    
        <div class="license-wrapper">
            <p>原文作者：<a href="https://LolipopJ.github.io">Lolipop</a>
            <p>原文链接：<a href="https://lolipopj.github.io/2022/01/08/start-telegram-bot/">https://lolipopj.github.io/2022/01/08/start-telegram-bot/</a>
            <p>发表日期：<a href="https://lolipopj.github.io/2022/01/08/start-telegram-bot/">January 8th 2022, 4:00:00 pm</a>
            <p>更新日期：<a href="https://lolipopj.github.io/2022/01/08/start-telegram-bot/">January 10th 2022, 4:00:00 pm</a>
            <p>版权声明：本文采用<a rel="license noopener" target="_blank" href="http://creativecommons.org/licenses/by-nc/4.0/">知识共享署名-非商业性使用 4.0 国际许可协议</a>进行许可</p>
        </div>
    
    <!-- paginator -->
    <ul class="post-paginator">
        <li class="next">
            
                <div class="nextSlogan">Next Post</div>
                <a href="/2022/01/12/random-get-me-a-picture/" title="这位客官，要来一张我珍藏许久的图片吗">
                    <div class="nextTitle">这位客官，要来一张我珍藏许久的图片吗</div>
                </a>
            
        </li>
        <li class="previous">
            
                <div class="prevSlogan">Previous Post</div>
                <a href="/2021/08/18/build-my-resume/" title="把自己的简历做成 Web 页面">
                    <div class="prevTitle">把自己的简历做成 Web 页面</div>
                </a>
            
        </li>
    </ul>
    <!-- comment -->
    
        <div class="post-comment">
            <!-- 来必力 City 版安装代码 -->


            

            

            
    <div id="gitalk-container"></div>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1.7.2/dist/gitalk.css">
    <script src="https://cdn.jsdelivr.net/npm/gitalk@1.7.2/dist/gitalk.min.js"></script>
    <script>
        let idOption = 'Sat Jan 08 2022 16:00:00 GMT+0000'
        
            idOption = location.pathname
        
        const gitalk = new Gitalk({
            clientID: '3e27d4e7935138a80cd8',
            clientSecret: 'cd3eda2bf0740e7a51b8b611ade908eb95590e45',
            repo: 'LolipopJ.github.io',
            owner: 'LolipopJ',
            admin: ["LolipopJ"],
            id: idOption,
            distractionFreeMode: false,
            createIssueManually: false,
        })
        gitalk.render('gitalk-container')
    </script>
    <noscript>为正常使用 Gitalk 评论功能，您需要激活 JavaScript</noscript>


            <!-- utteranc评论 -->


            <!-- partial('_partial/comment/changyan') -->
            <!--PC版-->


            
            

            

        </div>
    
    <!-- timeliness note -->
    <!-- idea from: https://hexo.fluid-dev.com/posts/hexo-injector/#%E6%96%87%E7%AB%A0%E6%97%B6%E6%95%88%E6%80%A7%E6%8F%90%E7%A4%BA -->
    
    <!-- Mathjax -->
    
</main>

                <!-- profile -->
                
            </div>
            <footer class="footer footer-unloaded">
    <!-- social  -->
    
        <div class="social">
            
    
        
            
                <a href="mailto:lolipop0703@qq.com" class="iconfont-archer email" title=email ></a>
            
        
    
        
            
                <a href="//github.com/LolipopJ" class="iconfont-archer github" target="_blank" title=github></a>
            
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
                <a href="https://twitter.com/Lolipop_0703" class="iconfont-archer twitter" target="_blank" title=twitter></a>
            
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            
                <a href="/atom.xml" class="iconfont-archer rss" target="_blank" title=rss></a>
            
        
    


        </div>
    
    <!-- powered by Hexo  -->
    <div class="copyright">
        <span id="hexo-power">Powered by <a href="https://hexo.io/" target="_blank">Hexo</a></span><span class="iconfont-archer power">&#xe635;</span><span id="theme-info">theme <a href="https://github.com/fi3ework/hexo-theme-archer" target="_blank">Archer</a></span>
    </div>
    <!-- website approve for Chinese user -->
    
        <div class="website-approve">
            
                <span id="icp-approve" class="icp-approve">
                    <a href="https://beian.miit.gov.cn/" target="_blank">蜀ICP备 2021015698号</a>
                </span>
            
            
                
                <img class="beian-img" src="/assets/beian.png" />
                <span id="beian-approve" class="beian-approve">
                    <a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=51010802001109" target="_blank">京公网安备 51010802001109号</a>
                </span>
            
        </div>
    
    <!-- 不蒜子  -->
    
        <div class="busuanzi-container">
            
             
                <span id="busuanzi_container_site_pv">PV: <span id="busuanzi_value_site_pv"></span> :)</span>
            
        </div>
    	
</footer>

        </div>
        <!-- toc -->
        
            <div class="toc-wrapper toc-wrapper-loding" style=







    top:50vh;

>
                <div class="toc-catalog">
                    <span class="iconfont-archer catalog-icon">&#xe613;</span><span>CATALOG</span>
                </div>
                <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9D%E5%A7%8B%E5%8C%96-Koa-%E9%A1%B9%E7%9B%AE"><span class="toc-number">1.</span> <span class="toc-text">初始化 Koa 项目</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%9E%E6%8E%A5%E5%88%B0-Telegram-Bot"><span class="toc-number">2.</span> <span class="toc-text">连接到 Telegram Bot</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84-Bot"><span class="toc-number">2.1.</span> <span class="toc-text">创建新的 Bot</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%8E-Bot-%E5%BB%BA%E7%AB%8B%E8%BF%9E%E6%8E%A5"><span class="toc-number">2.2.</span> <span class="toc-text">与 Bot 建立连接</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E7%BD%91%E7%BB%9C%E9%92%A9%E5%AD%90%E4%B8%8E-Bot-%E4%BA%A4%E4%BA%92"><span class="toc-number">2.3.</span> <span class="toc-text">使用网络钩子与 Bot 交互</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Bot-%E8%B5%B7%E5%A7%8B%E8%84%9A%E6%89%8B%E6%9E%B6"><span class="toc-number">2.4.</span> <span class="toc-text">Bot 起始脚手架</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96-Github-Issues-%E7%9A%84%E8%AF%84%E8%AE%BA%E5%B9%B6%E8%BD%AC%E5%8F%91%E7%BB%99-Telegram-%E9%A2%91%E9%81%93"><span class="toc-number">3.</span> <span class="toc-text">获取 Github Issues 的评论并转发给 Telegram 频道</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9E%E6%8E%A5%E5%88%B0%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">3.1.</span> <span class="toc-text">连接到数据库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8-ORM-%E7%AE%A1%E7%90%86%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">3.2.</span> <span class="toc-text">使用 ORM 管理数据库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A-Issue-%E4%B8%AD%E7%9A%84%E6%9C%80%E6%96%B0%E8%AF%84%E8%AE%BA"><span class="toc-number">3.3.</span> <span class="toc-text">获取指定 Issue 中的最新评论</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9A%E6%97%B6%E8%BD%AC%E5%8F%91%E8%AF%84%E8%AE%BA%E5%88%B0-Telegram-%E9%A2%91%E9%81%93"><span class="toc-number">3.4.</span> <span class="toc-text">定时转发评论到 Telegram 频道</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%AB%A0"><span class="toc-number">4.</span> <span class="toc-text">参考文章</span></a></li></ol>
            </div>
        
        <!-- sidebar -->
        <div class="sidebar sidebar-hide">
    <ul class="sidebar-tabs sidebar-tabs-active-0">
        <li class="sidebar-tab-archives"><span class="iconfont-archer">&#xe67d;</span><span class="tab-name">Archive</span></li>
        <li class="sidebar-tab-tags"><span class="iconfont-archer">&#xe61b;</span><span class="tab-name">Tag</span></li>
        <li class="sidebar-tab-categories"><span class="iconfont-archer">&#xe666;</span><span class="tab-name">Cate</span></li>
    </ul>
    <div class="sidebar-content sidebar-content-show-archive">
        <div class="sidebar-panel-archives">
    <!-- 在 ejs 中将 archive 按照时间排序 -->
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    
    
    
    <div class="total-and-search">
        <div class="total-archive">
        Total : 31
        </div>
        <!-- search  -->
        
            <div class="site-search site-search-loading popup-trigger">
                <span class="iconfont-archer search-icon">&#xe627;</span>
            </div>
        
    </div>
    
    <div class="post-archive">
    
        
            
            
            <div class="archive-year"> 2022 </div>
            <ul class="year-list">
            
        
        <li class="archive-post-item">
            <span class="archive-post-date">02/12</span>
            <a class="archive-post-title" href="/2022/02/11/connect-with-pgsql/">连接到 Windows 端的 PostgreSQL 数据库</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">01/13</span>
            <a class="archive-post-title" href="/2022/01/12/random-get-me-a-picture/">这位客官，要来一张我珍藏许久的图片吗</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">01/09</span>
            <a class="archive-post-title" href="/2022/01/08/start-telegram-bot/">从零开始使用 Telegram Bot</a>
        </li>
    
        
            
            
                
                </ul>
            
            <div class="archive-year"> 2021 </div>
            <ul class="year-list">
            
        
        <li class="archive-post-item">
            <span class="archive-post-date">08/19</span>
            <a class="archive-post-title" href="/2021/08/18/build-my-resume/">把自己的简历做成 Web 页面</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">08/13</span>
            <a class="archive-post-title" href="/2021/08/12/github-jsdelivr-hold-image/">使用 jsDelivr 加速 Github 仓库搭建自己的图床服务</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">08/07</span>
            <a class="archive-post-title" href="/2021/08/06/editorconfig-prettier/">使用 EditorConfig 和 Prettier 优雅地配置 VSCode 代码格式化</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">07/10</span>
            <a class="archive-post-title" href="/2021/07/09/switch-travis-to-github-workflow/">更换持续集成工具，从 Travis 到 Github Actions</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">07/08</span>
            <a class="archive-post-title" href="/2021/07/07/browser-behind-visit-url/">在浏览器中输入 URL 到显示网页，背后发生了什么</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">06/26</span>
            <a class="archive-post-title" href="/2021/06/25/web-font-for-hexo-theme-archer/">为 Archer 主题更换字体</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">06/25</span>
            <a class="archive-post-title" href="/2021/06/24/website-deployment-docker-nginx/">使用基于 Docker 的 Nginx 部署静态网页项目</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">06/09</span>
            <a class="archive-post-title" href="/2021/06/08/linux-project-v/">在 Linux 系统下启用 Project-V</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">06/04</span>
            <a class="archive-post-title" href="/2021/06/03/euler-install-mysql/">在 Euler 系统上离线安装 MySQL 5.7</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">05/20</span>
            <a class="archive-post-title" href="/2021/05/19/js-use-class/">漫谈 JavsScript 类（Class）的使用</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">05/18</span>
            <a class="archive-post-title" href="/2021/05/17/js-closure/">漫谈 JavsScript 闭包</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">05/11</span>
            <a class="archive-post-title" href="/2021/05/10/js-hoisting/">JavsScript 变量提升和函数提升</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">05/08</span>
            <a class="archive-post-title" href="/2021/05/07/js-debounce-throttle/">函数防抖和节流，以及在 Vue 中的运用</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">04/26</span>
            <a class="archive-post-title" href="/2021/04/25/windows-install-grpc/">Windows 系统编译安装基于 C++ 的 gRPC</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">04/22</span>
            <a class="archive-post-title" href="/2021/04/21/linux-docker-install-grpc/">Linux 系统编译安装基于 C++ 的 gRPC</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">04/20</span>
            <a class="archive-post-title" href="/2021/04/19/linux-docker-gcc-update/">Linux 容器更新或降级 GCC 版本</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">03/29</span>
            <a class="archive-post-title" href="/2021/03/28/protobuf-learning/">Protobuf 学习笔记</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">03/17</span>
            <a class="archive-post-title" href="/2021/03/16/amap-import-vue/">在 Nuxt.js 中引入高德地图并实现定位及逆地理编码</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">03/16</span>
            <a class="archive-post-title" href="/2021/03/15/tencent-map-api-get-current-location/">使用腾讯位置服务进行 Web 前端定位</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">03/10</span>
            <a class="archive-post-title" href="/2021/03/09/xxx-is-not-a-symbolic-link/">提示 *** is not a symbolic link 解决方案</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">03/03</span>
            <a class="archive-post-title" href="/2021/03/02/nodejs-eslint-prettier/">Nuxt 项目配置 ESLint 和 Prettier 检查并规范代码质量与格式</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">02/23</span>
            <a class="archive-post-title" href="/2021/02/22/write-md-parser/">Webpack 读取本地 Markdown 文件并进行预处理</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">02/21</span>
            <a class="archive-post-title" href="/2021/02/20/tg-mtproto-one-click/">一键安装并配置 MTProto Proxy 代理 Telegram</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">02/19</span>
            <a class="archive-post-title" href="/2021/02/18/hexo-github-actions-ci-cd/">使用 Github Actions 持续集成与部署 Hexo 博客</a>
        </li>
    
        
            
            
                
                </ul>
            
            <div class="archive-year"> 2020 </div>
            <ul class="year-list">
            
        
        <li class="archive-post-item">
            <span class="archive-post-date">12/29</span>
            <a class="archive-post-title" href="/2020/12/28/ISO-IEC-IEEE-42010-des/">IEEE 1471（ISO/IEC/IEEE 42010）架构描述方法</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">09/28</span>
            <a class="archive-post-title" href="/2020/09/27/pytorch-install-windows-10/">PyTorch 在 Windows 10 系统下的环境配置及安装</a>
        </li>
    
        
            
            
                
                </ul>
            
            <div class="archive-year"> 2019 </div>
            <ul class="year-list">
            
        
        <li class="archive-post-item">
            <span class="archive-post-date">12/27</span>
            <a class="archive-post-title" href="/2019/12/26/archer-theme-update-log/">基于 Archer 主题的博客开发</a>
        </li>
    
        
        <li class="archive-post-item">
            <span class="archive-post-date">12/27</span>
            <a class="archive-post-title" href="/2019/12/26/hello-hexo-world/">Hello Hexo World</a>
        </li>
    
    </div>
</div>

        <div class="sidebar-panel-tags">
    <div class="sidebar-tags-name">
        
            <span class="sidebar-tag-name" data-tags="开发日志">
                <span class="iconfont-archer">&#xe606;</span>
                开发日志
            </span>
        
            <span class="sidebar-tag-name" data-tags="Vue-2">
                <span class="iconfont-archer">&#xe606;</span>
                Vue-2
            </span>
        
            <span class="sidebar-tag-name" data-tags="软件体系架构设计">
                <span class="iconfont-archer">&#xe606;</span>
                软件体系架构设计
            </span>
        
            <span class="sidebar-tag-name" data-tags="JavaScript">
                <span class="iconfont-archer">&#xe606;</span>
                JavaScript
            </span>
        
            <span class="sidebar-tag-name" data-tags="Node">
                <span class="iconfont-archer">&#xe606;</span>
                Node
            </span>
        
            <span class="sidebar-tag-name" data-tags="Nuxt">
                <span class="iconfont-archer">&#xe606;</span>
                Nuxt
            </span>
        
            <span class="sidebar-tag-name" data-tags="Promise">
                <span class="iconfont-archer">&#xe606;</span>
                Promise
            </span>
        
            <span class="sidebar-tag-name" data-tags="博客开发">
                <span class="iconfont-archer">&#xe606;</span>
                博客开发
            </span>
        
            <span class="sidebar-tag-name" data-tags="Hexo">
                <span class="iconfont-archer">&#xe606;</span>
                Hexo
            </span>
        
            <span class="sidebar-tag-name" data-tags="hexo-theme-archer">
                <span class="iconfont-archer">&#xe606;</span>
                hexo-theme-archer
            </span>
        
            <span class="sidebar-tag-name" data-tags="计算机网络">
                <span class="iconfont-archer">&#xe606;</span>
                计算机网络
            </span>
        
            <span class="sidebar-tag-name" data-tags="网络安全">
                <span class="iconfont-archer">&#xe606;</span>
                网络安全
            </span>
        
            <span class="sidebar-tag-name" data-tags="密码学">
                <span class="iconfont-archer">&#xe606;</span>
                密码学
            </span>
        
            <span class="sidebar-tag-name" data-tags="resume">
                <span class="iconfont-archer">&#xe606;</span>
                resume
            </span>
        
            <span class="sidebar-tag-name" data-tags="CSS">
                <span class="iconfont-archer">&#xe606;</span>
                CSS
            </span>
        
            <span class="sidebar-tag-name" data-tags="Github-actions">
                <span class="iconfont-archer">&#xe606;</span>
                Github-actions
            </span>
        
            <span class="sidebar-tag-name" data-tags="rxjs">
                <span class="iconfont-archer">&#xe606;</span>
                rxjs
            </span>
        
            <span class="sidebar-tag-name" data-tags="PostgreSQL">
                <span class="iconfont-archer">&#xe606;</span>
                PostgreSQL
            </span>
        
            <span class="sidebar-tag-name" data-tags="Windows">
                <span class="iconfont-archer">&#xe606;</span>
                Windows
            </span>
        
            <span class="sidebar-tag-name" data-tags="EditorConfig">
                <span class="iconfont-archer">&#xe606;</span>
                EditorConfig
            </span>
        
            <span class="sidebar-tag-name" data-tags="Prettier">
                <span class="iconfont-archer">&#xe606;</span>
                Prettier
            </span>
        
            <span class="sidebar-tag-name" data-tags="VSCode">
                <span class="iconfont-archer">&#xe606;</span>
                VSCode
            </span>
        
            <span class="sidebar-tag-name" data-tags="Linux">
                <span class="iconfont-archer">&#xe606;</span>
                Linux
            </span>
        
            <span class="sidebar-tag-name" data-tags="MySQL">
                <span class="iconfont-archer">&#xe606;</span>
                MySQL
            </span>
        
            <span class="sidebar-tag-name" data-tags="Github">
                <span class="iconfont-archer">&#xe606;</span>
                Github
            </span>
        
            <span class="sidebar-tag-name" data-tags="jsDiliver">
                <span class="iconfont-archer">&#xe606;</span>
                jsDiliver
            </span>
        
            <span class="sidebar-tag-name" data-tags="ES6">
                <span class="iconfont-archer">&#xe606;</span>
                ES6
            </span>
        
            <span class="sidebar-tag-name" data-tags="GCC">
                <span class="iconfont-archer">&#xe606;</span>
                GCC
            </span>
        
            <span class="sidebar-tag-name" data-tags="Docker">
                <span class="iconfont-archer">&#xe606;</span>
                Docker
            </span>
        
            <span class="sidebar-tag-name" data-tags="CPP">
                <span class="iconfont-archer">&#xe606;</span>
                CPP
            </span>
        
            <span class="sidebar-tag-name" data-tags="gRPC">
                <span class="iconfont-archer">&#xe606;</span>
                gRPC
            </span>
        
            <span class="sidebar-tag-name" data-tags="ESLint">
                <span class="iconfont-archer">&#xe606;</span>
                ESLint
            </span>
        
            <span class="sidebar-tag-name" data-tags="Protobuf">
                <span class="iconfont-archer">&#xe606;</span>
                Protobuf
            </span>
        
            <span class="sidebar-tag-name" data-tags="机器学习">
                <span class="iconfont-archer">&#xe606;</span>
                机器学习
            </span>
        
            <span class="sidebar-tag-name" data-tags="PyTorch">
                <span class="iconfont-archer">&#xe606;</span>
                PyTorch
            </span>
        
            <span class="sidebar-tag-name" data-tags="Telegram">
                <span class="iconfont-archer">&#xe606;</span>
                Telegram
            </span>
        
            <span class="sidebar-tag-name" data-tags="Bot">
                <span class="iconfont-archer">&#xe606;</span>
                Bot
            </span>
        
            <span class="sidebar-tag-name" data-tags="Koa">
                <span class="iconfont-archer">&#xe606;</span>
                Koa
            </span>
        
            <span class="sidebar-tag-name" data-tags="Sequelize">
                <span class="iconfont-archer">&#xe606;</span>
                Sequelize
            </span>
        
            <span class="sidebar-tag-name" data-tags="Travis">
                <span class="iconfont-archer">&#xe606;</span>
                Travis
            </span>
        
            <span class="sidebar-tag-name" data-tags="MTProto">
                <span class="iconfont-archer">&#xe606;</span>
                MTProto
            </span>
        
            <span class="sidebar-tag-name" data-tags="Nginx">
                <span class="iconfont-archer">&#xe606;</span>
                Nginx
            </span>
        
            <span class="sidebar-tag-name" data-tags="Markdown">
                <span class="iconfont-archer">&#xe606;</span>
                Markdown
            </span>
        
            <span class="sidebar-tag-name" data-tags="Webpack">
                <span class="iconfont-archer">&#xe606;</span>
                Webpack
            </span>
        
    </div>
    <div class="iconfont-archer sidebar-tags-empty">&#xe678;</div>
    <div class="tag-load-fail" style="display: none; color: #ccc; font-size: 0.6rem;">
        缺失模块，请参考主题文档进行安装配置：https://github.com/fi3ework/hexo-theme-archer#%E5%AE%89%E8%A3%85%E4%B8%BB%E9%A2%98
    </div> 
    <div class="sidebar-tags-list"></div>
</div>

        <div class="sidebar-panel-categories">
    <div class="sidebar-categories-name">
    
        <span class="sidebar-category-name" data-categories="学习琐事">
            <span class="iconfont-archer">&#xe60a;</span>
            学习琐事
        </span>
    
        <span class="sidebar-category-name" data-categories="前端开发">
            <span class="iconfont-archer">&#xe60a;</span>
            前端开发
        </span>
    
        <span class="sidebar-category-name" data-categories="后端开发">
            <span class="iconfont-archer">&#xe60a;</span>
            后端开发
        </span>
    
        <span class="sidebar-category-name" data-categories="技术琐事">
            <span class="iconfont-archer">&#xe60a;</span>
            技术琐事
        </span>
    
    </div>
    <div class="iconfont-archer sidebar-categories-empty">&#xe678;</div>
    <div class="sidebar-categories-list"></div>
</div>

    </div>
</div>

        <!-- site-meta -->
        <script>
    var siteMetaRoot = "/"
    if (siteMetaRoot === "undefined") {
        siteMetaRoot = '/'
    }
    var siteMeta = {
        url: "https://LolipopJ.github.io",
        root: siteMetaRoot,
        author: "Lolipop"
    }
</script>

        <!-- import experimental options here -->
        <!-- Custom Font -->

    <!-- Check browser compatibility of CSS variables -->
    <script>
        if (browserSupportCSSVariables === undefined) {
            var browserSupportCSSVariables = window.CSS && window.CSS.supports && window.CSS.supports('--a', 0);
        }
    </script>
    <script>
        if (browserSupportCSSVariables) {
            var customFontName = 'Noto Sans SC:n3,n4,n5,n7'
            var customFontUrl = 'https://fonts.googleapis.cnpmjs.org/css2?family=Noto+Sans+SC:wght@300;400;500;700&amp;display=swap'
            if (!customFontName) {
                console.log('Custom font name is not set or read failed');
            }
            if (!customFontUrl) {
                console.log('Custom font url is not set or read failed');
            }
        } else {
            console.error('Current browser doesn\'t support custom font.')
        }
    </script>
    <script src="/scripts/customFontLoader.js?v=20211217" defer></script>


        <!-- main func -->
        <script src="/scripts/main.js?v=20211217"></script>
        <!-- dark mode -->
        <script src="/scripts/dark.js?v=20211217"></script>
        <!-- fancybox -->
        <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" defer></script>
        <!-- algolia -->
        
            <div class="site-search site-search-loading">
    <div class="algolia-popup popup">
        <div class="algolia-search">
            <div class="algolia-search-input-icon">
                <i class="fa fa-search"></i>
            </div>
            <div class="algolia-search-input" id="algolia-search-input"></div>
            <div class="popup-btn-close">
                <i class="iconfont-archer">&#xe609;</i>
            </div>
        </div>

        <div class="algolia-results">
            <div id="algolia-stats" class="algolia-stats"></div>
            <div id="algolia-hits"></div>
            <div id="algolia-pagination" class="algolia-pagination"></div>
        </div>
    </div>
</div>

            <script src="/scripts/search.js?v=20211217" defer></script>
        
        <!-- busuanzi -->
        
            <script src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>
        
        <!-- CNZZ -->
        
        <!-- async load share.js -->
        
            <script src="/scripts/share.js?v=20211217" async></script>
        
        <!-- mermaid -->
        
    </body>
</html>
